#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
    # 初始化方法
    # 查找元素
    # 点击
    # 获取value属性方法
    # 截图
"""
import time

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait


class BaseCalculator:
    # 初始化方法
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.get("https://cal.supfree.net/")

    # 查找元素
    def base_find_element(self, loc, timeout=30, poll=0.5):
        return WebDriverWait(self.driver,
                             timeout=timeout,
                             poll_frequency=poll).until(lambda x: x.find_element(*loc))

    # 点击
    def base_click(self, loc):
        self.base_find_element(loc).click()

    # 获取value属性方法
    def base_get_value(self, loc):
        self.base_find_element(loc).get_attribute("value")

    # 截图
    def base_get_img(self):
        self.driver.get_screenshot_as_file(f"../image/{time.strftime('%Y_%m_%d %H_%M_%S')}.png")
